<?php

/**
 * @name: HOTN AnimeList
 * @author: HammerOnTheNail
 * @link: http://code.google.com/p/hotnanimelist/
 */

// Simple Machines Forum kezelő

class hotn_animelist_forum
{
	var $SMF_DIR, $SMF_PREFIX;
	
	function hotn_animelist_forum()
	{
		global $HOTN_ANIMELIST_OPTIONS;
		define('SMF', 1);
		
		$this->SMF_DIR = e_BASE.$HOTN_ANIMELIST_OPTIONS['forum_dir']."/";
		@include($this->SMF_DIR . '/Settings.php');
		
		$this->SMF_PREFIX = $db_prefix;
		
		RETURN TRUE;
	}
	
	// MySQL SELECT
	function select($table,$row,$where)
	{
		if (is_array($table))
		{
			
		}
		else
		{
			$table = $this->SMF_PREFIX.$table;
		}
		$sql = "SELECT ".$row." FROM ".$table." WHERE ".$where;
		return $this->query($sql);
	}
	
	// MySQL lekérdezés elküldése
	function query($sql)
	{
		$result = mysql_query($sql);
		while($row = mysql_fetch_array($result))
		{
			$return[] = $row;
		}
		
		return $return;
	}
	
	// Bejegyzés hozzáadása
	function hotn_animelist_forum_create($project_name,$project_forum_text,$project_mode)
	{
		/*
		 A gyönyörűszép új topic hozzáadása
		 
		 majd egyszer talán meglesz ez is :D
		 
		 	DELETE FROM smf_log_floodcontrol WHERE (logTime < 1267206951 AND ip = '') OR logTime < 1267206948
			REPLACE INTO smf_log_floodcontrol (ip, logTime) VALUES (SUBSTRING('', 1, 16), 1267206953)
			INSERT INTO smf_messages (ID_BOARD, ID_TOPIC, ID_MEMBER, subject, body, posterName, posterEmail, posterTime, posterIP, smileysEnabled, modifiedName, icon) VALUES (8, 0, 1, SUBSTRING('Teszt topic 5', 1, 255), SUBSTRING('5-ös számú topic', 1, 65534), SUBSTRING('newplayer', 1, 255), SUBSTRING('karasztamas@gmail.com', 1, 255), 1267206953, SUBSTRING('unknown', 1, 255), 1, '', SUBSTRING('xx', 1, 16))
			INSERT INTO smf_topics (ID_BOARD, ID_MEMBER_STARTED, ID_MEMBER_UPDATED, ID_FIRST_MSG, ID_LAST_MSG, locked, isSticky, numViews, ID_POLL) VALUES (8, 1, 1, 4, 4, 0, 0, 0, 0)
			UPDATE smf_messages SET ID_TOPIC = 4 WHERE ID_MSG = 4 LIMIT 1
			UPDATE smf_settings SET value = value + 1 WHERE variable = 'totalTopics' LIMIT 1
			DELETE FROM smf_log_search_subjects WHERE ID_TOPIC = 4
			INSERT IGNORE INTO smf_log_search_subjects (word, ID_TOPIC) VALUES ('teszt', 4), ('topic', 4), ('5', 4)
			UPDATE smf_messages SET ID_MSG_MODIFIED = 4 WHERE ID_MSG = 4
			UPDATE smf_boards SET numPosts = numPosts + 1, numTopics = numTopics + 1 WHERE ID_BOARD = 8 LIMIT 1
			REPLACE INTO smf_log_topics (ID_TOPIC, ID_MEMBER, ID_MSG) VALUES (4, 1, 4 + 1)
			UPDATE smf_members SET posts = posts + 1 WHERE ID_MEMBER = 1 LIMIT 1
			SELECT ID_GROUP, minPosts FROM smf_membergroups WHERE minPosts != -1
			UPDATE smf_members SET ID_POST_GROUP = CASE WHEN posts >= 500 THEN 8 WHEN posts >= 250 AND posts <= 500 THEN 7 WHEN posts >= 100 AND posts <= 250 THEN 6 WHEN posts >= 50 AND posts <= 100 THEN 5 WHEN posts >= 0 AND posts <= 50 THEN 4 ELSE 0 END WHERE ID_MEMBER = 1 LIMIT 1
			UPDATE smf_settings SET value = value + 1 WHERE variable = 'totalMessages' LIMIT 1
			UPDATE smf_settings SET value = '4' WHERE variable = 'maxMsgID' LIMIT 1
			UPDATE smf_boards SET ID_LAST_MSG = 4, ID_MSG_UPDATED = 4 WHERE ID_BOARD IN (8) LIMIT 1
			UPDATE smf_log_boards SET ID_MSG = 4 WHERE ID_MEMBER = 1 AND ID_BOARD IN (7)
			SELECT mem.ID_MEMBER, mem.emailAddress, mem.notifyOnce, mem.notifySendBody, mem.lngfile, ln.sent, mem.ID_GROUP, mem.additionalGroups, b.memberGroups, mem.ID_POST_GROUP FROM (smf_log_notify AS ln, smf_members AS mem, smf_boards AS b) WHERE ln.ID_BOARD = 8 AND b.ID_BOARD = 8 AND mem.ID_MEMBER != 1 AND mem.is_activated = 1 AND mem.notifyTypes != 4 AND ln.ID_MEMBER = mem.ID_MEMBER GROUP BY mem.ID_MEMBER ORDER BY mem.lngfile
			UPDATE smf_log_notify SET sent = 1 WHERE ID_BOARD = 8 AND ID_MEMBER != 1
		 
		 */
		
		return 0;
	}
	
	// Topicok kiírása
	function hotn_animelist_forum_show_topic()
	{
		$sql = "SELECT
			IFNULL(b.ID_BOARD, 0) AS ID_BOARD, b.ID_PARENT, b.name AS bName, b.description, b.childLevel,
			b.boardOrder, b.countPosts, b.memberGroups, b.ID_THEME, b.override_theme,
			b.permission_mode, c.ID_CAT, c.name AS cName, c.catOrder, c.canCollapse
		FROM {$this->SMF_PREFIX}categories AS c
			LEFT JOIN {$this->SMF_PREFIX}boards AS b ON (b.ID_CAT = c.ID_CAT)
		ORDER BY c.catOrder, b.childLevel, b.boardOrder";
		
		return $this->query($sql);
	}
}